<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>WVJS 测试</title>
    <style type="text/css">
        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
        }
        .wrapper {
            height: 100%;
            padding: 0 7px;
            overflow: scroll;
            padding: 50px 0 0 0;
        }
    </style>
    <script>
            window.onload = function() {
                console.log('navigator.userAgent: ', navigator.userAgent)
                const container = document.getElementById('userAgentContainer');
                container.innerHTML = navigator.userAgent;
            }
            function setupWebViewJavascriptBridge(callback) {
                if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
                if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
                window.WVJBCallbacks = [callback];
                var WVJBIframe = document.createElement('iframe');
                WVJBIframe.style.display = 'none';
                WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
                document.documentElement.appendChild(WVJBIframe);
                setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
            }
             setupWebViewJavascriptBridge(function(bridge) {
                bridge.registerHandler('testJavascriptHandler', function(data, responseCallback) {
                    console.log('JS got data: ', JSON.stringify(data))
                    let responseData = { 'testJavascriptHandler':'responseCallback from js', 'value':{'b':'bb'} }
                    responseCallback(responseData)
                })
            })
            function callTestArkTs() {
                setupWebViewJavascriptBridge(function(bridge) {
                    let data = {'testArkTsCallback': 'callHandler from js', 'value': { 'y' : 'yy' }}
                    bridge.callHandler('testArkTsCallback', data, function(response) {
                        console.log('JS got response: ', JSON.stringify(response))
                        alert('JS got response: ' + JSON.stringify(response))
                    })
                })
            }
    </script>
</head>
<body>
    <p>当前UserAgent：</p>
    <div id="userAgentContainer" style="color: #000000"></div>
    <br>
    <div class="wrapper">
        <button onclick="callTestArkTs()">testArkTsCallback</button>
    </div>
</body>
</html>